#include<iostream>
#include"CDate.h"

void display(CDate date1);
long long int date_to_second(CDate date);
int date_to_Day(CDate date);

int main(){
    using namespace std;
    CDate setDateTest;
    switch (setDateTest.setDate(1, 1, 1, 1, 1, 1))
    {
    case 1:
        cout << "set year error.\n"; break;
    case 2:
        cout << "set month error.\n"; break;
    case 3:
        cout << "set day error.\n"; break;
    case 4:
        cout << "set hour error.\n"; break;
    case 5:
        cout << "set minute error.\n"; break;
    case 6:
        cout << "Set second error.\n"; break;
    default:
        cout << "setDate() Done.\n"; break;
    }

    CDate addTimeTest;
    addTimeTest.setDate(1,1,1,1,1,1);
    long long int before = date_to_second(addTimeTest);
    int second;
    cout << "Please enter a second to add: ";
    cin >> second;
    if(second < 0){
        addTimeTest.addTime(second);
        cout << "Second can not smaller than 0.\n";
    }else if(second < 60){
        addTimeTest.addTime(second);
    }else if(second < 3600){
        addTimeTest.addTime(second);
    }else if (second < 86400){
        addTimeTest.addTime(second);
    }else{
        addTimeTest.addTime(second);
    }
    long long int after = date_to_second(addTimeTest);
    if(after == second + before)
        cout << "addTime test Done.\n";
    else
        cout << "addTime error.\n";
    
    CDate subtractionTest, subtracted;
    subtractionTest.setDate(2019, 7, 21, 14, 15, 26);
    subtracted.setDate(2011, 7, 22, 16, 22, 38);
    int num1 = date_to_Day(subtractionTest);
    int num2 = date_to_Day(subtracted);

    if(subtractionTest - subtracted == num1 - num2)
        cout << "subtraction test Done.\n";
    else
        cout << "subtraction error.\n";

    cout << "All tests Done.\n";
    system("pause");
    return 0;
}

void display(CDate date1){
    using namespace std;
    cout << date1.getYear() << "-" << date1.getMonth() << "-" << date1.getDay() << "-" << date1.getHour() << "-" 
    << date1.getMinute() << "-" << date1.getSecond() << endl;
}

long long int date_to_second(CDate date){
    long long int year = date.getYear();
    long long int month = date.getMonth();
    long long int day = date.getDay();
    long long int hour = date.getHour();
    long long int minute = date.getMinute();
    long long int second = date.getSecond();

    month += year * 12;
    day += month * 30;
    hour += day * 24;
    minute += hour * 24;
    second += minute * 60;
    
    return second;
}

int date_to_Day(CDate date){
    int year = date.getYear();
    int month = date.getMonth();
    int day = date.getDay();
    
    return year * 365 + month * 30 + day;
}